//
//  NMySetTableViewController.m
//  News
//
//  Created by zhangtao on 2018/10/29.
//  Copyright © 2018年 zt.td. All rights reserved.
//

#import "NMySetTableViewController.h"
#import "NMyWalletPsdSetController.h"
@interface NMySetTableViewController ()

@end

@implementation NMySetTableViewController
{
    NSArray *titleArray;
    NSArray *classArray;
}

-(instancetype)initWithStyle:(UITableViewStyle)style{
    return [super initWithStyle:UITableViewStyleGrouped];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = MAIN_BG_COLOR;
    self.title = @"设置";
    self.tableView.sectionHeaderHeight = 10;
    self.tableView.sectionFooterHeight = 0;
}

#pragma mark - Table view data source

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section != 2) {
        return 10;
    }

    return 40;
}
//
//-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
//    return .1;
//}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *view = [UIView new];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 3;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    if(section == 0) return 1;
    if(section == 1) return 2;
    if(section == 2) return 1;
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 40;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.textLabel.font = BASE_FONT;
    cell.detailTextLabel.font = [UIFont systemFontOfSize:15];
    cell.backgroundColor = [UIColor whiteColor];
    if (indexPath.section != 2) {
        cell.textLabel.text = self.titleArray[indexPath.section][indexPath.row];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        
        if (indexPath.section == 0 && indexPath.row == 0) {
            cell.detailTextLabel.text = @"138****7799";
        }
    }else{
        UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ACEWidth, 40)];
        lab.text = @"退出登录";
        lab.textAlignment = NSTextAlignmentCenter;
        lab.textColor = RGB(212, 52, 64, 1);
        [cell addSubview:lab];
    }
    
    // Configure the cell...
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UIViewController *controller = [[NSClassFromString(self.classArray[indexPath.section][indexPath.row]) alloc]init];
    [self.navigationController pushViewController:controller animated:YES];
    if (indexPath.section == 1) {
        if (indexPath.row == 0) {
            NWebViewController *vc = [[NWebViewController alloc] init];
            vc.netHtml = [NSString stringWithFormat:@"%@%@",baseH5Url,H5_feedback];
            vc.title = @"意见反馈";
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        } else if (indexPath.row == 1) {
            NWebViewController *vc = [[NWebViewController alloc] init];
            vc.netHtml = [NSString stringWithFormat:@"%@%@",baseH5Url,H5_about];
            vc.title = @"关于我们";
            self.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
    }
}

-(NSArray *)titleArray{
    if (!titleArray) {
        titleArray = @[@[@"修改绑定手机"],@[@"意见反馈",@"关于我们"],@[@"退出登录"]];
    }
    return titleArray;
}

-(NSArray *)classArray{
    if (!classArray) {
        classArray = @[@[@"NMyWalletPsdSetController"],@[@"",@"",@""],@[@""]];
    }
    return classArray;
}

/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
